#include <cairo.h>
#include <gtk/gtk.h>

static gboolean
on_expose_event (GtkWidget * widget,
                 GdkEventExpose * event, gpointer data)
{
        cairo_t *cr;

        cr = gdk_cairo_create (widget->window);

        cairo_set_source_rgba (cr, 0, 0, 0,1);
        cairo_set_line_width (cr, 10);

        /* 绘制三种线条 */
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
        cairo_move_to (cr, 40, 60);
        cairo_line_to (cr, 360, 60);
        cairo_stroke (cr);

        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
        cairo_move_to (cr, 40, 150);
        cairo_line_to (cr, 360, 150);
        cairo_stroke (cr);

        cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
        cairo_move_to (cr, 40, 240);
        cairo_line_to (cr, 360, 240);
        cairo_stroke (cr);

        cairo_set_line_width (cr, 1.5);

        /* 左侧的线 */
        cairo_move_to (cr, 40, 40);
        cairo_line_to (cr, 40, 260);
        cairo_stroke (cr);

        /* 右侧左边的线 */
        cairo_move_to (cr, 360, 40);
        cairo_line_to (cr, 360, 260);
        cairo_stroke (cr);

        /* 右侧右边的线 */
        cairo_move_to (cr, 365, 40);
        cairo_line_to (cr, 365, 260);
        cairo_stroke (cr);

        cairo_destroy (cr);

        return FALSE;
}


int
main (int argc,char *argv[])
{

        GtkWidget *window;
        GtkWidget *darea;

        gtk_init (&argc, &argv);

        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

        darea = gtk_drawing_area_new ();
        gtk_container_add (GTK_CONTAINER (window), darea);

        g_signal_connect (darea, "expose-event",
                          G_CALLBACK (on_expose_event),NULL);
        g_signal_connect (window, "destroy",
                          G_CALLBACK (gtk_main_quit),NULL);

        /* 设置窗口在屏幕正中间 */
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
        /* 设置窗口大小 */
        gtk_window_set_default_size (GTK_WINDOW(window),400,300);

        gtk_widget_show_all (window);

        gtk_main ();

        return 0;
}